package com.origon360.security;

import java.io.UnsupportedEncodingException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CridentialUtils {
	
	private static Log log = LogFactory.getLog(CridentialUtils.class);
	
	public static final String UTF_8_ENCODING = "UTF-8";
	
	
	public static String getUTF8String(byte[] bytes) throws IllegalStateException{
		
		try {
			return new String(bytes, UTF_8_ENCODING);
			
		} catch (UnsupportedEncodingException e) {
			log.fatal("Unable to obtain UTF-8 Encoded string", e);
			
			throw new IllegalStateException("UTF-8 unavailable", e);
		}
	}
	
		
	public static byte[] getUTF8Bytes(String string) throws IllegalStateException{
		try {
			return string.getBytes(UTF_8_ENCODING);
			
		} catch (UnsupportedEncodingException e) {
			log.fatal("Unable to obtain UTF-8 encoded String", e);
			
			throw new IllegalStateException("UTF-8 encoding unavailable", e);
		}
	}
		
		
	}

